-- created by kumiler
-- on 2023/1/6 15:20
-- DESC


insert overwrite table spmi_dim.dim_spmi_pcp_capacity_cost_mt partition(mt)
select id,
       bill_month,
       send_financial_center_name,
       send_financial_center_code,
       destination_name,
       destination_code,
       cost,
       create_time,
       'BF160' as fee_type_code,
       '运力成本' as fee_type_name,
       substring (bill_month,1,7) as mt
from (
         select *, rank() over (partition by bill_month order by to_date(create_time) desc) as time_rank
         from spmi_ods.spmi_pcp_capacity_cost
         where dt = '{{ execution_date | cst_ds }}'
     ) t
where time_rank = 1